package MyTickerText;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.util.HorizontalAlign;

import braindamagestudio.com.app.fight.MainGameActivity;

public class DialogBox {

	private MyTickerText _tickerText;
	private Sprite _dialogBackground;
	private Scene _attachScene;
	
	private int x;
	private int y;
	
	public DialogBox(int positionX,int positionY,TextureRegion background,Scene attachScene)
	{
		x = positionX;
		y = positionY;
		_attachScene = attachScene;
		
		_dialogBackground = new Sprite(0,500,background)
		{
			@Override
			public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) 
			{
				OnGreenTouch(pSceneTouchEvent,pTouchAreaLocalX,pTouchAreaLocalY);
				return false;
			}
		};	
	}
	
	public void OnGreenTouch(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY)
	{
		if(onGreenTouchListenr!=null)
		{
			onGreenTouchListenr.onGreenTouchListenr(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
		}
	}
	
	public OnGreenTouchListenr onGreenTouchListenr = null;
	
	public interface OnGreenTouchListenr
	{
		public void onGreenTouchListenr(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY);
	}
	
	
	public void showDialogText(String text)
	{
		if(_dialogBackground.hasParent() == false)
		{
			_attachScene.attachChild(_dialogBackground);
		}
		
		_dialogBackground.detachChild(_tickerText);
		_tickerText =  new MyTickerText(60, 50, MainGameActivity.mFont,text, HorizontalAlign.LEFT, 30);
		_dialogBackground.attachChild(_tickerText);
	}
	
	public void endDialog()
	{
		_attachScene.detachChild(_dialogBackground);
	}
}
